{extend name="public/base"}

{block name="title"}
我的爱车
{/block}

{block name="style"}
{css href="/static/wechat/css/center.css" /}
{/block}

{block name="body"}
<div class="pageControl editCarMsg">
    <div class="msui_nav msui_navTop">
        <a class="msui_navTop-back" href="javascript:history.back();"><i class="micon-back"></i></a>
        <h1 class="msui_navTop-title">选择爱车</h1>
    </div>
    <div class="weui-top">
        {empty name="data"}
        <div class="weui-msg">
            <div class="weui-msg__icon-area"><i class="micon-myCar_default"></i></div>
            <div class="weui-msg__text-area">
                <h2 class="weui-msg__title">您还没有任何车辆信息哦</h2>
            </div>
        </div>
        {else /}
        {volist name="data" id="vo"}
        <div class="msui_table msui_tableCom">
            <div class="msui_tabCell-check">
                <!--<input type="checkbox" class="weui-check" name="chooseBox" value="pay3">-->
                {eq name="vo.is_default|default=0" value="0"}
                <i class="my-car-check" data-id="{$vo.id}"></i>
                {else /}
                <i class="my-car-check my-car-checked" data-id="{$vo.id}"></i>
                {/eq}
            </div>
            <div class="msui_tabCell-img msui_tableImg-circle to_info" data-id="{$vo.id}">
                <img src="{$vo.image}">
            </div>
            <div class="msui_tabCell-content to_info" data-id="{$vo.id}">
                <p class="fs085 cl-3333">{$vo.name}</p>
                <p class="fs075 cl-9999">{$vo.mileage}Km</p>
            </div>
            <div class="msui_tabCell-button">
                <a class="cl-orange bc-orange" href="{:url('save_my_car', ['id' => $vo['id'], 'brand_id' => $vo['brand_id'], 'model_id' => $vo['model_id']])}">编辑</a>
            </div>
        </div>
        {/volist}
        {/empty}


        <div class="msui_button">
            <div class="msui_button-bd">
                <a href="{:url('brand_list')}" class="msui_button-content">添加车辆</a>
            </div>
        </div>
    </div>

</div>
{/block}
{block name="javascript"}
<script>
    $(function () {
        $(".my-car-check").click(function () {
            var _this = $(this), is_default = 1, id = _this.data('id');
            if (_this.hasClass('my-car-checked')) {
                if (!confirm('确定取消默认车辆？')) return false;
                is_default = 0;
            } else {
                if (!confirm('确定设置默认车辆？')) return false;
            }

            $.get('{:url("save_default_car")}', {id : id,  is_default: is_default}, function (msg) {
                if (msg.code == 200) {
                    alert("设置成功！！");
                    window.location.reload();
                } else {
                    var code = msg.code;
                    $.alert(error_code[code]);
                }
            });
        });

        // 跳转详情页
        $(".to_info").click(function () {
            var id = $(this).data('id');
            window.location.href = "{:url('my_car_info')}?id=" + id;
        });
    });
</script>
{/block}
